
import { WeElement, define } from 'omi'

import { get , post , getUiAndLogin , toastErr  } from '../../utils/util'

import { LoginUrl } from '../../api/api.js'

//获取应用实例
const app = getApp()

import './index.css'

define('page-my', class extends WeElement {
  config = {
    navigationBarTitleText: '庐山西海瑶池湾度假山庄'
  }

  data = {
    top:"",
    user_head:"",
    icon:[],
    userInfo: {},
    hasUserInfo: false,
  }

  install() {
    this.data.top = require('../../images/wd_banner.png') ;

    if(app.globalData.access_token){
      this.data.userInfo = app.globalData.userInfo ;
      this.data.hasUserInfo = true;
    }else{
      this.data.userInfo.avatarUrl = require('../../images/user.png');

    }
    this.data.icon = [require('../../images/icon_order.png'),
       require('../../images/icon_card.png'),
       require('../../images/icon_youhui.png'),
       require('../../images/icon_invite.png'),
       require('../../images/icon_my.png'),
       require('../../images/icon_aright.png'),
        require('../../images/cart-y.jpg')];
    this.update();
  }
  getUserInfo = (evt)=>{ 
    getUiAndLogin(evt.detail,app, ()=>{
      this.data.userInfo = evt.detail.userInfo
      
      this.data.hasUserInfo = true
      this.update()
    }) ;
  }  
  //积分明细
  points = () => {
    wx.navigateTo({
      url: '../points/index',
    })
  }
  //优惠券
  coupon = () => {
    wx.navigateTo({
      url: '../my/coupon/index',
    })
  }
  //我的订单
  my_order = () => {
    wx.navigateTo({
      url: '../my/my_order/index',
    })
  }
  //购物车
  my_cart = () => {
    wx.navigateTo({
      url: '../my/my_cart/index',
    })
  }

  //我的卡包
  my_card = () => {
    toastErr('暂未开放')
    return;
    wx.navigateTo({
      url: '../my/my_card/index',
    })
  }
  //兑换优惠券
  my_youhui = () => {
    toastErr('暂未开放')
    return;
    wx.navigateTo({
      url: '../my/my_youhui/index',
    })
  }
  //邀请
  my_invitation = () => {
    toastErr('暂未开放')
    return;
    wx.navigateTo({
      url: '../my/my_invitation/index',
    })
  }
  //关于我们
  about_us = () => {
    wx.navigateTo({
      url: '../my/about_us/index',
    })
  }
  picker=()=>{
    console.log("11");
    this.data.picker=true;
    this.update()
  }
  render() {
    return (
      <view class="container">
        <image class="top" src={top}></image>
        <view class="content">
        <view class="mid_top">
          <view class="mid_top_con">
           {/* 头像 */}
          {/* 点击登陆 */}
            <view class="user_info">
                <image class="user_head" src={userInfo.avatarUrl}></image>
                { app.globalData.access_token ? 
                    <view class="mid_username">{userInfo.nickName}</view>
                    :
                    <button class='login' open-type="getUserInfo" bindgetuserinfo="getUserInfo" >立即登陆</button> 
                } 
            </view>
            <view class="mid_usercard">
              <view bindtap={this.points}>积分<view>000分</view></view>
              <view bindtap={this.my_card}>会员卡<view>1张</view></view>
              <view bindtap={this.coupon}>优惠卡<view>0张</view></view>
            </view>
          </view>
        </view>
        <view class="mid_mid">
          <view class="order" bindtap={this.my_order}>
            <image class="icon_order" src={icon[0]}></image>
            <view class="my_order">我的订单</view>
            <image class="icon_right" src={icon[5]}></image>
          </view>
          <view class="order" bindtap={this.my_cart}>
            <image class="icon_order" src={icon[6]}></image>
            <view class="my_order">购物车</view>
            <image class="icon_right" src={icon[5]}></image>
          </view>
          <view class="order" bindtap={this.my_card}>
            <image class="icon_order" src={icon[1]}></image>
            <view class="my_order">我的卡包</view>
            <image class="icon_right" src={icon[5]}></image>
          </view>
        </view>
        <view class="mid_bot">
          <view class="order" bindtap={this.my_youhui}>
            <image class="icon_order" src={icon[2]}></image>
            <view class="my_order">兑换优惠券</view>
            <image class="icon_right" src={icon[5]}></image>
          </view>
          <view class="order" bindtap={this.my_invitation}>
            <image class="icon_order" src={icon[3]}></image>
            <view class="my_order">我邀请的人</view>
            <image class="icon_right" src={icon[5]}></image>
          </view>
          <view class="order" bindtap={this.about_us}>
            <image class="icon_order" src={icon[4]}></image>
            <view class="my_order">关于我们</view>
            <image class="icon_right" src={icon[5]}></image>
          </view>
        </view>
        </view>
      </view>
      
    )
  }
})